package com.rabbiter.oes.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rabbiter.oes.entity.ApiResult;
import com.rabbiter.oes.entity.College;
import com.rabbiter.oes.serviceimpl.CollegeServiceImpl;
import com.rabbiter.oes.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/college")
public class CollegeController {
    @Autowired
    private CollegeServiceImpl collegeService;

    @GetMapping("/selectAllCollege/{page}/{size}")
    public ApiResult selectAllCollege(@PathVariable Integer page, @PathVariable Integer size){
        Page<College> college = new Page<>(page,size);
        IPage<College> collegePage = collegeService.findAll(college);
        return ApiResultHandler.buildApiResult(200,"查询所有学院",collegePage);
    }

    @GetMapping("/selectAllCollege/{id}")
    public  ApiResult selectCoolegeById(@PathVariable int id){
        return  ApiResultHandler.success(collegeService.selectCollegeById(id));
    }

    @PostMapping("/update")
    public  ApiResult updateCollege(@RequestBody College college){
        return ApiResultHandler.success(collegeService.updateCollege(college));
    }
    @DeleteMapping("/delete/{id}")
    public ApiResult deleteCollege(@PathVariable int id){
        return ApiResultHandler.success(collegeService.deleteCollege(id));
    }
    @PostMapping("/add")
    public  ApiResult addCollege(@RequestBody College college){
        return ApiResultHandler.success(collegeService.addCollege(college));
    }
}